<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of check_matrix</title>
  <meta name="keywords" content="check_matrix">
  <meta name="description" content="check_matrix(A) --- check if A is a valid adjacency matrix for a graph">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html &copy; 2003 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../m2html.css">
</head>
<body>
<a name="_top"></a>
<div><a href="../index.html">Home</a> &gt;  <a href="index.html">matgraph</a> &gt; check_matrix.m</div>

<!--<table width="100%"><tr><td align="left"><a href="../index.html"><img alt="<" border="0" src="../left.png">&nbsp;Master index</a></td>
<td align="right"><a href="index.html">Index for matgraph&nbsp;<img alt=">" border="0" src="../right.png"></a></td></tr></table>-->

<h1>check_matrix
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>check_matrix(A) --- check if A is a valid adjacency matrix for a graph</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>function ok = check_matrix(A) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre class="comment"> check_matrix(A) --- check if A is a valid adjacency matrix for a graph</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../matlabicon.gif)">
</ul>
This function is called by:
<ul style="list-style-image:url(../matlabicon.gif)">
</ul>
<!-- crossreference -->


<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function ok = check_matrix(A)</a>
0002 <span class="comment">% check_matrix(A) --- check if A is a valid adjacency matrix for a graph</span>
0003 
0004 ok = 0;
0005 
0006 <span class="comment">% make sure matrix is equare</span>
0007 [nr,nc] = size(A);
0008 <span class="keyword">if</span> (nr ~= nc) 
0009     <span class="keyword">return</span>
0010 <span class="keyword">end</span>
0011 
0012 <span class="comment">% see if the matrix is zero-one</span>
0013 B = (A&gt;0); <span class="comment">% convert to logical (so 0,1).</span>
0014 <span class="keyword">if</span> (nnz(A-B)&gt;0)
0015     <span class="keyword">return</span>
0016 <span class="keyword">end</span>
0017 
0018 <span class="comment">% check if symmetric</span>
0019 <span class="keyword">if</span> (nnz(A-A')&gt;0)
0020     <span class="keyword">return</span>
0021 <span class="keyword">end</span>
0022 
0023 <span class="comment">% check the diagonal</span>
0024 <span class="keyword">if</span> (any(diag(A)&gt;0)) 
0025     <span class="keyword">return</span>
0026 <span class="keyword">end</span>
0027 
0028 <span class="comment">% all tests passed</span>
0029 ok = 1;</pre></div>
<hr><address>Generated on Fri 30-Apr-2010 07:51:16 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/">m2html</a></strong> &copy; 2003</address>
</body>
</html>